Keep synthesized layer_norm gamma/beta at normalized_shape - #55
Merged
gokulkrishna98 merged 2 commits intoAug 12, 2026
Merged
Conversation
When elementwise_affine=False, replace_layer_norm built the identity gamma/beta as a flat numel-element vector, so a layer_norm over normalized_shape (4, 8) produced a composite taking tensor<32xf32> gamma/beta while its declaration said axes = [1, 2]. The body reshaped them back before broadcasting, so numerics were correct, but the composite boundary was inconsistent with the declared axes and differed from the elementwise_affine=True case, where ATen's real params arrive already shaped (4, 8). A consumer that implements the composite from its declaration instead of inlining the body sees a rank-1 gamma against two normalized axes. Build the constants with np.ones/np.zeros at normalized_shape so both paths present the same interface, and drop the now-dead reshape.
gokulkrishna98
force-pushed
the
dev/gokul/layer_norm_test_fix
branch
from
August 11, 2026 18:08
6daf3e0 to
5ef1bd1
Compare
gokulkrishna98
marked this pull request as ready for review
August 11, 2026 20:17
Lewis300
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
elementwise_affine=False,replace_layer_normsynthesized the identity gamma/beta as a flatnumel-element vector, so a layer norm overnormalized_shape = (4, 8)emitted a composite takingtensor<32xf32>gamma/beta while its declaration saidaxes = [1, 2]. Numerics were correct (the body reshaped them back), but the composite boundary contradicted the declared axes and differed from theelementwise_affine=Truecase, where ATen's params arrive already shaped(4, 8).Build the constants at
normalized_shapeso both modes present the same interface, and drop the now-dead reshape.Test plan:
pytest tests/ops/test_ops_ir.py -k LayerNorm(new IR regression test)pytest tests/ops/test_ops.py -k "LayerNorm or layer_norm"pytest tests/ops -n auto